{include file='common/head' /}
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
              <a><cite>购物券活动管理</cite></a>
              <a><cite>活动列表</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="name"  placeholder="活动名称" autocomplete="off" class="layui-input" value="{$get.name|default=''}">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="status">
                                <option value="">状态筛选</option>
                                <option value="1" {if condition="$get['status'] eq 1"}selected{/if}>上架</option>
                                <option value="2" {if condition="$get['status'] eq 2"}selected{/if}>下架</option>
                            </select>
                        </div>
                        <!--日期选择-->
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input"  autocomplete="off" placeholder="开始日" name="start" id="start" value="{$get.start|default=''}">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn" onclick="xadmin.open('添加购物券活动','/admin/volumes/volumes_add','','',true)">
                        <i class="layui-icon"></i>活动
                    </button>
                    <span style="line-height:40px;float: right;">共有数据：{$count} 条</span>
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th style="text-align: center;width: 10%">id</th>
                            <th style="text-align: center;width: 10%">活动名称</th>
                            <th style="text-align: center;width: 10%">活动封面</th>
                            <th style="text-align: center;width: 9%">活动状态</th>
                            <th style="text-align: center;min-width:200px;">开始/结束-时间</th>
                            <th style="text-align: center;min-width:150px;">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {volist name="list" id="v"}
                        <tr>
                            <td style="text-align: center;">{$v.id}</td>
                            <td style="text-align: center;">{$v.title}</td>
                            <td style="text-align: center;"><a href="{$v.share}" target="_blank"><img src="{$v.share}" height="50"></a></td>
                            <td style="text-align: center;" class="td-status">
                                {if condition="$v['status'] eq 1"}
                                <span class="layui-btn layui-btn-normal layui-btn-mini">上架</span>
                                {else /}
                                <span class="layui-btn layui-btn-danger layui-btn-mini">下架</span>
                                {/if}
                            </td>
                            <td style="text-align: center;">
                                开始时间: <span style="color: steelblue;">{:date('Y-m-d H:i:s',$v['start_time'])}</span>
                                <hr>
                                结束时间: <span style="color: steelblue;">{if condition="$v['end_time'] neq '0'"}{:date('Y-m-d',$v['end_time'])}{else/}不限{/if}</span>
                            </td>
                            <td style="text-align: center;" class="td-manage">
                                <button class="layui-btn layui-btn layui-btn-xs" title="编辑"  onclick="xadmin.open('编辑','/admin/volumes/volumes_edit?id={$v.id}','','',true)" href="javascript:;">
                                    <i class="layui-icon">&#xe642;</i>编辑
                                </button>
                                {if condition="$v['status'] eq 1"}
                                <button class="layui-btn-danger layui-btn layui-btn-xs" onclick="end(this,{$v['id']})" href="javascript:;">
                                    活动下架
                                </button>
                                {else /}
                                <button class="layui-btn-normal layui-btn layui-btn-xs" onclick="start(this,{$v['id']})" href="javascript:;">
                                    活动上架
                                </button>
                                {/if}
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        {$page}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['form','laydate'], function(){
        var  form = layui.form;
        var laydate  = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        // 监听全选
        // form.on('checkbox(checkall)', function(data){
        //     if(data.elem.checked){
        //         $('tbody input').prop('checked',true);
        //     }else{
        //         $('tbody input').prop('checked',false);
        //     }
        //     form.render('checkbox');
        // });
    });

    function start(obj,id){
        layer.confirm('确认要上架此活动吗？',function(index){
            $.ajax({
                url:"{:url('Volumes/volumes_status')}",
                type: "post",
                data:{id:id,'type':'start'},
                dataType:"json",
                success:function (res) {
                    if(res.code == 200){
                        $(obj).attr('onclick','end(this,'+id+')');
                        $(obj).html('下架活动');
                        $(obj).addClass('layui-btn-danger');
                        $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-danger').addClass('layui-btn-normal').html('上架');
                        layer.msg(res.msg, {icon: 1,time:1000});
                    }else{
                        layer.alert(res.msg, {icon:2,time:1000});
                    }
                },
                error:function(e){
                    layer.alert("网络错误", {icon:5,time:1000});
                },
            });
        });
    }

    function end(obj,id){
        layer.confirm('确认要下架此活动吗？',function(index){
            $.ajax({
                url:"{:url('Volumes/volumes_status')}",
                type: "post",
                data:{id:id,'type':'end'},
                dataType:"json",
                success:function (res) {
                    if(res.code == 200){
                        $(obj).attr('onclick','start(this,'+id+')');
                        $(obj).html('上架活动');
                        $(obj).removeClass('layui-btn-danger');
                        $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-normal').addClass('layui-btn-danger').html('下架');
                        layer.msg(res.msg, {icon: 1,time:1000});
                    }else{
                        layer.alert(res.msg, {icon:2,time:1000});
                    }
                },
                error:function(e){
                    layer.alert("网络错误", {icon:5,time:1000});
                },
            });
        });
    }
</script>
{include file='common/scroll' /}
{include file='common/footer' /}